<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /**
 
  dp[index] = 以特定字符结尾的最大数量
初始pre=1 : pre是连续的个数;
如果字母是连续的就pre++
否则pre = 1;
 */

   /**
 * @param {string} p
 * @return {number}
 */
/**
 * @param {string} p
 * @return {number}
 */
 var findSubstringInWraproundString = function(p) {
    let dp = new Array(26).fill(0);
    let k = 0;

    for(let i=0;i<p.length;i++){
        if((i>0&&p[i].charCodeAt()-p[i-1].charCodeAt()+26)%26===1){
            ++k
        }else{
            k = 1
        }
        dp[p[i].charCodeAt()-'a'.charCodeAt()] = Math.max(dp[p[i].charCodeAt()-'a'.charCodeAt()],k)

    }
    return eval(dp.join('+'))
};

console.log(findSubstringInWraproundString('zab'));
  </script>
</body>

</html>